package com.menhai.personmanagement.controller;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.annotations.Param;
import org.apache.poi.ss.usermodel.CellStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.menhai.personmanagement.entity.Codelist;
import com.menhai.personmanagement.entity.FollowupRecord;
import com.menhai.personmanagement.entity.FollowupRecordCondition;
import com.menhai.personmanagement.entity.MbReportCard;
import com.menhai.personmanagement.services.FollowupRecordService;
import com.menhai.personmanagement.services.ICodelistService;
import com.menhai.personmanagement.services.MbIndexInputService;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import lombok.extern.slf4j.Slf4j;
/**
 * <p>
 * 随访记录表 前端控制器
 * </p>
 *
 * @author shikun
 * @since 2021-11-25
 */

@Slf4j
@RestController
@RequestMapping("/followupRecord")
public class FollowupRecordController {

	private static final Logger logger = LoggerFactory.getLogger(FollowupRecordController.class);

     @Autowired
     private FollowupRecordService followupRecordService;

     @Autowired
     private MbIndexInputService mbIndexInputService;

     @Autowired
     private ICodelistService iCodelistService;

     @RequestMapping("/add")
     public Object addFollowupRecord(FollowupRecord followupRecord,String followupDateStr,String zzjxcsfCxsfrqStr) throws Exception{
		 SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 Map<String, Object> map = null;
		 followupRecord.setFollowupDate(followupDateStr);
		 followupRecord.setZzjxcsfCxsfrq(zzjxcsfCxsfrqStr);
		 //取到患者所属医院
		 List<Map<String,Object>> list=mbIndexInputService.getOneByPopulation(followupRecord.getPersonNo());
		 if(list!=null&&list.size()>0){
			 String hosnum=list.get(0).get("hosnum")+"";
			 followupRecord.setHosnum(hosnum);
		 }
		 //新增随访记录
		 map = followupRecordService.addFollowupRecord(followupRecord);
		 return map;
     }


	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public Object editFollowupRecord(HttpServletRequest request, HttpServletResponse response, FollowupRecord followupRecord,String followupDateStr,String zzjxcsfCxsfrqStr) throws Exception {
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> map = null;
		followupRecord.setFollowupDate(followupDateStr);
		followupRecord.setZzjxcsfCxsfrq(zzjxcsfCxsfrqStr);
		//取到患者所属医院
		List<Map<String,Object>> list=mbIndexInputService.getOneByPopulation(followupRecord.getPersonNo());
		if(list!=null&&list.size()>0){
			String hosnum=list.get(0).get("hosnum")+"";
			followupRecord.setHosnum(hosnum);
		}
		//编辑随访记录
		map = followupRecordService.editFollowupRecord(followupRecord);
		return map;
	}

	@RequestMapping(value = "/getListByCondition", method = RequestMethod.POST)
	public Object getListByCondition(HttpServletRequest request, HttpServletResponse response, FollowupRecordCondition followupRecordCondition) throws Exception {
		List<Map<String,Object>> list = null;
		list = followupRecordService.getListByCondition(followupRecordCondition);
		return list;
	}

	@RequestMapping(value = "/getListByConditionByPage", method = RequestMethod.POST)
	public Object getListByConditionByPage(HttpServletRequest request, HttpServletResponse response, FollowupRecordCondition followupRecordCondition) throws Exception {
		IPage<FollowupRecordCondition> list = followupRecordService.getListByConditionByPage(followupRecordCondition,request.getParameter("hosnumarray"));
		return list;
	}

	@RequestMapping("/gecunrenshu")
	public List gecunrenshu(@RequestHeader(name = "userid") String userid, @Param("mbtype") String mbtype,@Param("hosnum") String hosnum){
		return followupRecordService.gecunrenshu(mbtype,userid,hosnum);
	}

	@RequestMapping(value = "/getOneById", method = RequestMethod.POST)
	public Object getOneById(HttpServletRequest request, HttpServletResponse response, FollowupRecordCondition followupRecordCondition) throws Exception {
		List<Map<String,Object>> list = null;
		list = followupRecordService.getOneById(followupRecordCondition);
		if(list.size()>0){
			return list.get(0);
		}
		return list;
	}

	//查询人口姓名集合
    @RequestMapping("/selectPopulationList")
    public Object selectPopulationList(HttpServletRequest request, HttpServletResponse response){
		String patientName = request.getParameter("patientName");
		String hosnum=request.getParameter("hosnum");
		return followupRecordService.getPopulationNameListByCondition(patientName,hosnum);
     }

  //按姓名获取报卡患者信息(计划内)
  @RequestMapping(value = "/selectNameListPlan", method = RequestMethod.POST)
  public Object selectNameListPlan(HttpServletRequest request, HttpServletResponse response) throws Exception {
	  List<Map<String,Object>> nameList=new ArrayList<Map<String,Object>>();
	  List<Map<String,Object>> reportCardList=null;
	  String patientName=request.getParameter("patientName");
	  String mbType=request.getParameter("mbType");
	  String hosnum=request.getParameter("hosnum");
	  String shstatus=request.getParameter("shstatus");
	  String sbstatus=request.getParameter("sbstatus");
	  String startDate=request.getParameter("startDate");
	  String endDate=request.getParameter("endDate");
	  String doctorId=request.getParameter("doctorId");
	  reportCardList=followupRecordService.getCardNameListPlanByCondition(patientName,mbType,hosnum,shstatus,sbstatus,startDate,endDate,doctorId);
	  if(reportCardList!=null&&reportCardList.size()>0){
		  Map<String,Object> map=new HashMap<String,Object>();
		  for(int i=0;i<reportCardList.size();i++){
			  map=new HashMap<String,Object>();
			  map.put("name",reportCardList.get(i).get("patientName"));
			  map.put("cardid",reportCardList.get(i).get("bkbh"));
			  map.put("personNo", reportCardList.get(i).get("populationid"));
			  map.put("info", reportCardList.get(i).get("planTime")+"  "+reportCardList.get(i).get("planType")+"  "+reportCardList.get(i).get("patientName"));
			  map.put("planDate", reportCardList.get(i).get("planDate"));
			  map.put("planTime", reportCardList.get(i).get("planTime"));
			  map.put("planid", reportCardList.get(i).get("planid"));
			  map.put("planType", reportCardList.get(i).get("planType"));
			  nameList.add(map);
		  }
	  }
	  return nameList;
  }

  //按姓名获取报卡患者信息
  @RequestMapping(value = "/selectNameListNoPlan", method = RequestMethod.POST)
  public Object selectNameListNoPlan(HttpServletRequest request, HttpServletResponse response) throws Exception {
	  List<Map<String,Object>> nameList=new ArrayList<Map<String,Object>>();
	  List<MbReportCard> reportCardList=null;
	  String patientName=request.getParameter("patientName");
	  String mbType=request.getParameter("mbType");
	  String hosnum=request.getParameter("hosnum");
	  String shstatus=request.getParameter("shstatus");
	  String sbstatus=request.getParameter("sbstatus");
	  String startDate=request.getParameter("startDate");
	  String endDate=request.getParameter("endDate");
	  String doctorId=request.getParameter("doctorId");
	  reportCardList=followupRecordService.getCardNameListNoPlanByCondition(patientName,mbType,hosnum,shstatus,sbstatus,startDate,endDate,doctorId);
	  if(reportCardList!=null&&reportCardList.size()>0){
		  Map<String,Object> map=new HashMap<String,Object>();
		  for(int i=0;i<reportCardList.size();i++){
			  map=new HashMap<String,Object>();
			  map.put("name",reportCardList.get(i).getPatientName());
			  map.put("cardid",reportCardList.get(i).getBkbh());
			  map.put("personNo", reportCardList.get(i).getPopulationid());
			  map.put("info", reportCardList.get(i).getPatientName()+"  "+reportCardList.get(i).getBkbh());
			  map.put("planDate", "");
			  map.put("planTime", "");
			  map.put("planid", "");
			  map.put("planType", "");
			  nameList.add(map);
		  }
	  }
	  return nameList;
  }

	//按姓名获取报卡患者信息
	@RequestMapping(value = "/selectNameList", method = RequestMethod.POST)
	public Object selectNameList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Map<String,Object>> nameList=new ArrayList<Map<String,Object>>();
		List<MbReportCard> reportCardList=null;
		String patientName=request.getParameter("patientName");
		String mbType=request.getParameter("mbType");
		String hosnum=request.getParameter("hosnum");
		String shstatus=request.getParameter("shstatus");
		String sbstatus=request.getParameter("sbstatus");
		String startDate=request.getParameter("startDate");
		String endDate=request.getParameter("endDate");
		reportCardList=followupRecordService.getCardNameListByCondition(patientName,mbType,hosnum,shstatus,sbstatus,startDate,endDate);
		if(reportCardList!=null&&reportCardList.size()>0){
			Map<String,Object> map=new HashMap<String,Object>();
			for(int i=0;i<reportCardList.size();i++){
				map=new HashMap<String,Object>();
				map.put("name",reportCardList.get(i).getPatientName());
				map.put("cardid",reportCardList.get(i).getBkbh());
				map.put("personNo", reportCardList.get(i).getPopulationid());
				map.put("info", reportCardList.get(i).getPatientName()+"  "+reportCardList.get(i).getBkbh());
				map.put("planDate", "");
				map.put("planTime", "");
				map.put("planid", "");
				map.put("planType", "");
				nameList.add(map);
			}
		}
		return nameList;
	}

	/**
	 * 查询随访提醒
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/selectSFTX", method = RequestMethod.POST)
	public Object selectSFTX(HttpServletRequest request, HttpServletResponse response,FollowupRecordCondition followupRecordCondition) throws Exception {
		String personName = request.getParameter("personName");
		String mbType = request.getParameter("mbType");
		String hosnum = request.getParameter("hosnum");
		return followupRecordService.selectSFTX(personName,hosnum,mbType,followupRecordCondition);
	}

	/**
	 * 三天随访提醒
	 * @param request
	 * @param response
	 * @param followupRecordCondition
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getTXList", method = RequestMethod.POST)
	public Object getTXList(HttpServletRequest request, HttpServletResponse response,FollowupRecordCondition followupRecordCondition) throws Exception {
		String planTime = request.getParameter("planTime");
		String hosnum = request.getParameter("hosnum");
		String mbType = request.getParameter("mbType");
		String userId = request.getParameter("userId");
		String hosnumStr = request.getParameter("hosnumarray");
		String[] hosnumArray = hosnumStr.split(",");
		return followupRecordService.getTXList(planTime,hosnum,mbType,userId,hosnumStr,hosnumArray);
	}

	/**
	 * 慢病数据统计汇总查询
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getMbsjtjhzListByYear", method = RequestMethod.POST)
	public Object getMbsjtjhzListByYear(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> mbsjtjhzList=new HashMap<String,Object>();
		String queryYear=request.getParameter("queryYear");
		String mbType=request.getParameter("mbType");
		String hosnum=request.getParameter("hosnum");
		String hosnumArray=request.getParameter("hosnumArray");
		mbsjtjhzList=followupRecordService.getMbsjtjhzListByYear(queryYear,mbType,hosnum,hosnumArray);
		return mbsjtjhzList;
	}


	/**
	 * @describe 药品统计
	 * @param hosnum
	 * @param mbType
	 * @Return java.util.List
	 * @Date 2022/2/9 15:16
	 * @author shikun
	 */
	@RequestMapping("/drugstatistics")
	public List drugstatistics(@Param("hosnum") String hosnum, @Param("mbType") String mbType){
		return followupRecordService.drugstatistics(hosnum, mbType);
	}


	/**
	 * 慢病分类人群统计查询
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getMbflrqtjbByYear", method = RequestMethod.POST)
	public Object getMbflrqtjbByYear(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryYear=request.getParameter("queryYear");
		String hosnum=request.getParameter("hosnum");
		resultList=followupRecordService.getMbflrqtjbByYear(queryYear,hosnum);
		return resultList;
	}

	@RequestMapping("/exportMbflrqtjbByYear")
    public void exportMbflrqtjbByYear(HttpServletRequest request, HttpServletResponse response){
         try {
			 String queryYear=request.getParameter("queryYear");
			 String hosnum=request.getParameter("hosnum");
              List<Map<String,Object>> list = followupRecordService.getMbflrqtjbByYear(queryYear,hosnum);

              ExcelWriter writer = ExcelUtil.getWriter();
              List<String> header0 = new LinkedList<>();
              header0.add(queryYear+"年慢性病病种分类统计表");
              header0.add("");
              header0.add("");
              header0.add("");
              header0.add("");
              header0.add("");
              header0.add("");
              header0.add("");
              writer.writeHeadRow(header0);
              writer.merge(0,0,0,7,null,false);
              List<String> header1 = new LinkedList<>();
              header1.add("村名");
              header1.add("慢性病病种");
              header1.add("");
              header1.add("");
              header1.add("");
              header1.add("");
              header1.add("");
              header1.add("");
              writer.writeHeadRow(header1);
              writer.merge(1,1,1,7,null,false);
              LinkedList<Object> header2 = new LinkedList<>();
              header2.add("");
              header2.add("高血压");
              header2.add("糖尿病");
              header2.add("冠心病");
              header2.add("肿瘤");
              header2.add("精神病");
              header2.add("其他");
              header2.add("合计");
              writer.writeHeadRow(header2);
              writer.merge(1, 2, 0, 0, null, false);
              List<List<String>> rows = new LinkedList<>();
              list.forEach(val -> {
				  Map<String,Object> map = val;
                  LinkedList<String> row = CollUtil.newLinkedList(map.get("hosname").toString(),map.get("gxynum").toString(),map.get("tnbnum").toString(),map.get("gxbnum").toString(),map.get("zlnum").toString(),map.get("jsbnum").toString(),map.get("othernum").toString(),map.get("num").toString());
				  rows.add(row);
              });
              writer.write(rows,true);
              response.setContentType("application/vnd.ms-excel;charset=utf-8");
              String fileName = new String("慢病分类人群统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
              response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
              ServletOutputStream out = null;
              try {
                   out = response.getOutputStream();
                   writer.flush(out, true);
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   // 关闭writer，释放内存
                   writer.close();
              }
              //此处记得关闭输出Servlet流
              IoUtil.close(out);

         } catch (Exception e) {
              e.printStackTrace();
         }
    }

	/**
	 * 慢病随访计划统计查询
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getMbsfjhtjbByDay", method = RequestMethod.POST)
	public Object getMbsfjhtjbByDay(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		resultList=followupRecordService.getMbsfjhtjbByDay(queryDay,hosnum,userid);
		return resultList;
	}

	@RequestMapping("/exportMbsfjhtjbByDay")
    public void exportMbsfjhtjbByDay(HttpServletRequest request, HttpServletResponse response){
         try {
			 String queryDay=request.getParameter("queryDay");
			 String hosnum=request.getParameter("hosnum");
			 String userid=request.getParameter("userid");
              List<Map<String,Object>> list = followupRecordService.getMbsfjhtjbByDay(queryDay,hosnum,userid);

              ExcelWriter writer = ExcelUtil.getWriter();
              List<String> header0 = new LinkedList<>();
              header0.add(queryDay+"日慢病随访计划统计表");
              writer.writeHeadRow(header0);
              writer.merge(0,0,0,8,null,false);
              List<String> header1 = new LinkedList<>();
              header1.add("村名");
              header1.add("医生");
              header1.add("高血压随访");
              header1.add("糖尿病随访");
              header1.add("冠心病随访");
              header1.add("肿瘤随访");
              header1.add("精神病随访");
              header1.add("其他随访");
              header1.add("合计");
              writer.writeHeadRow(header1);
              List<List<String>> rows = new LinkedList<>();
              list.forEach(val -> {
				  Map<String,Object> map = val;
                  LinkedList<String> row = CollUtil.newLinkedList(map.get("hosname").toString(),map.get("doctorName").toString(),map.get("gxynum").toString(),map.get("tnbnum").toString(),map.get("gxbnum").toString(),map.get("zlnum").toString(),map.get("jsbnum").toString(),map.get("othernum").toString(),map.get("num").toString());
				  rows.add(row);
              });
              writer.write(rows,true);


              response.setContentType("application/vnd.ms-excel;charset=utf-8");
              String fileName = new String("慢病随访计划统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
              response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
              ServletOutputStream out = null;
              try {
                   out = response.getOutputStream();
                   writer.flush(out, true);
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   // 关闭writer，释放内存
                   writer.close();
              }
              //此处记得关闭输出Servlet流
              IoUtil.close(out);

         } catch (Exception e) {
              e.printStackTrace();
         }
    }

	/**
	 * 慢病随访工作统计查询
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getMbsfgztjbByDay", method = RequestMethod.POST)
	public Object getMbsfgztjbByDay(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		resultList=followupRecordService.getMbsfgztjbByDay(queryDay,hosnum,userid);
		return resultList;
	}

	@RequestMapping("/exportMbsfgztjbByDay")
    public void exportMbsfgztjbByDay(HttpServletRequest request, HttpServletResponse response){
         try {
			 String queryDay=request.getParameter("queryDay");
			 String hosnum=request.getParameter("hosnum");
			 String userid=request.getParameter("userid");
              List<Map<String,Object>> list = followupRecordService.getMbsfgztjbByDay(queryDay,hosnum,userid);

              ExcelWriter writer = ExcelUtil.getWriter();
              List<String> header0 = new LinkedList<>();
              header0.add(queryDay+"日慢病随访工作统计表");
              writer.writeHeadRow(header0);
              writer.merge(0,0,0,8,null,false);
              List<String> header1 = new LinkedList<>();
              header1.add("村名");
              header1.add("医生");
              header1.add("高血压随访");
              header1.add("糖尿病随访");
              header1.add("冠心病随访");
              header1.add("肿瘤随访");
              header1.add("精神病随访");
              header1.add("其他随访");
              header1.add("合计");
              writer.writeHeadRow(header1);
              List<List<String>> rows = new LinkedList<>();
              list.forEach(val -> {
				  Map<String,Object> map = val;
                  LinkedList<String> row = CollUtil.newLinkedList(map.get("hosname").toString(),map.get("doctorName").toString(),map.get("gxynum").toString(),map.get("tnbnum").toString(),map.get("gxbnum").toString(),map.get("zlnum").toString(),map.get("jsbnum").toString(),map.get("othernum").toString(),map.get("num").toString());
				  rows.add(row);
              });
              writer.write(rows,true);


              response.setContentType("application/vnd.ms-excel;charset=utf-8");
              String fileName = new String("慢病随访工作统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
              response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
              ServletOutputStream out = null;
              try {
                   out = response.getOutputStream();
                   writer.flush(out, true);
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   // 关闭writer，释放内存
                   writer.close();
              }
              //此处记得关闭输出Servlet流
              IoUtil.close(out);

         } catch (Exception e) {
              e.printStackTrace();
         }
    }

	/**
	 * 慢病日工作量统计查询
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getMbrgzltjbByDay", method = RequestMethod.POST)
	public Object getMbrgzltjbByDay(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		resultList=followupRecordService.getMbrgzltjbByDay(queryDay,hosnum,userid);
		return resultList;
	}

	/**
	 * 中医体检医生站工作量统计表数据加载
	 * @author: 高云雷
	 * @createTime: 2023/8/16 15:44
	 * @param: [request, response]
	 * @return: java.lang.Object
	 **/
	@RequestMapping(value = "/getGzlList", method = RequestMethod.POST)
	public Object getGzlList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		logger.info("进入--中医体检医生站工作量统计表数据加载");
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		resultList=followupRecordService.getGzlList(queryDay,hosnum,userid);
		return resultList;
	}

	/**
	 * 中医体检医生站工作量统计表--数据加载
	 * @author: 高云雷
	 * @createTime: 2023/8/24 8:45
	 * @param: [request, response]
	 * @return: java.lang.Object
	 **/
	@RequestMapping(value = "/getGZLTJList", method = RequestMethod.POST)
	public Object getGZLTJList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		logger.info("进入--中医体检医生站工作量统计表--数据加载");
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		resultList=followupRecordService.getGZLTJList(queryDay,hosnum);
		return resultList;
	}

	/**
	 * 风险统计统计表--数据加载
	 * @author: 高云雷
	 * @createTime: 2023/8/24 8:45
	 * @param: [request, response]
	 * @return: java.lang.Object
	 **/
	@RequestMapping(value = "/getFXZSList", method = RequestMethod.POST)
	public Object getFXZSList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		logger.info("进入--中医体检医生站工作量统计表--数据加载");
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		resultList=followupRecordService.getFXZSList(queryDay,hosnum);
		return resultList;
	}

	/**
	 * 中医体检信息统计表-数据加载
	 * @author: 高云雷
	 * @createTime: 2023/8/22 15:18
	 * @param: [request, response]
	 * @return: java.lang.Object
	 **/
	@RequestMapping(value = "/getTZXXList", method = RequestMethod.POST)
	public Object getTZXXList(HttpServletRequest request, HttpServletResponse response){
		logger.info("进入--中医体检信息统计表--数据加载（阴，阳，血瘀，湿气）");
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		resultList=followupRecordService.getTZXXList(queryDay,hosnum);
		return resultList;
	}

	/**
	 * 体质分析数据加载
	 * @author: 高云雷
	 * @createTime: 2023/8/16 15:43
	 * @param: [request, response]
	 * @return: java.lang.Object
	 **/
	@RequestMapping(value = "getTZFX",method = RequestMethod.POST)
	public Object getTZFX(HttpServletRequest request,HttpServletResponse response){
		logger.info("进入--体质分析数据加载");
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		System.out.println(queryDay + "  -=-=- " + hosnum + "-----" + userid);
		resultList=followupRecordService.getTZFX(queryDay,hosnum,null);
		return resultList;
	}

	/**
	 * 脏腑辩证数据加载
	 * @author: 高云雷
	 * @createTime: 2023/8/16 15:43
	 * @param: [request, response]
	 * @return: java.lang.Object
	 **/
	@RequestMapping(value = "getZFBZList",method = RequestMethod.POST)
	public Object getZFBZList(HttpServletRequest request,HttpServletResponse response){
		logger.info("进入--脏腑辩证数据加载");
		String queryDay=request.getParameter("queryDay");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		return followupRecordService.getZFBZList(queryDay,hosnum);
	}

	@RequestMapping("/exportMbrgzltjbByDay")
    public void exportMbrgzltjbByDay(HttpServletRequest request, HttpServletResponse response){
         try {
			 String queryDay=request.getParameter("queryDay");
			 String hosnum=request.getParameter("hosnum");
			 String userid=request.getParameter("userid");
              List<Map<String,Object>> list = followupRecordService.getMbrgzltjbByDay(queryDay,hosnum,userid);

              ExcelWriter writer = ExcelUtil.getWriter();
              List<String> header0 = new LinkedList<>();
              header0.add(queryDay+"工作量统计表");
              writer.writeHeadRow(header0);
              writer.merge(0,0,0,2,null,false);
              List<String> header1 = new LinkedList<>();
              header1.add("医生");
              header1.add("所属区域");
              header1.add("测量次数");
              writer.writeHeadRow(header1);
              List<List<String>> rows = new LinkedList<>();
              list.forEach(val -> {
				  Map<String,Object> map = val;
                  LinkedList<String> row = CollUtil.newLinkedList(map.get("doctorName").toString(),map.get("hosname").toString(),map.get("jknum").toString());
				  rows.add(row);
              });
              writer.write(rows,true);
			 writer.setColumnWidth(0,20);
			 writer.setColumnWidth(1,50);
			 writer.setColumnWidth(2,20);


              response.setContentType("application/vnd.ms-excel;charset=utf-8");
              String fileName = new String("日工作量统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
              response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
              ServletOutputStream out = null;
              try {
                   out = response.getOutputStream();
                   writer.flush(out, true);
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   // 关闭writer，释放内存
                   writer.close();
              }
              //此处记得关闭输出Servlet流
              IoUtil.close(out);

         } catch (Exception e) {
              e.printStackTrace();
         }
    }

	/**
	 * 慢病月度工作量统计查询
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getMbydgzltjbByYear", method = RequestMethod.POST)
	public Object getMbydgzltjbByYear(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		String queryYear=request.getParameter("queryYear");
		String hosnum=request.getParameter("hosnum");
		String userid=request.getParameter("userid");
		resultList=followupRecordService.getMbydgzltjbByYear(queryYear,hosnum,userid);
		return resultList;
	}

	@RequestMapping("/exportMbydgzltjbByYear")
    public void exportMbydgzltjbByYear(HttpServletRequest request, HttpServletResponse response){
         try {
			 String queryYear=request.getParameter("queryYear");
			 String hosnum=request.getParameter("hosnum");
			 String userid=request.getParameter("userid");
              List<Map<String,Object>> list = followupRecordService.getMbydgzltjbByYear(queryYear,hosnum,userid);

              ExcelWriter writer = ExcelUtil.getWriter();
              List<String> header0 = new LinkedList<>();
              header0.add(queryYear+"年月度工作量统计表");
              writer.writeHeadRow(header0);
              writer.merge(0,0,0,14,null,false);
              List<String> header1 = new LinkedList<>();
              header1.add("所属区域");
              header1.add("医生");
              header1.add("一月");
              header1.add("二月");
              header1.add("三月");
              header1.add("四月");
              header1.add("五月");
              header1.add("六月");
              header1.add("七月");
              header1.add("八月");
              header1.add("九月");
              header1.add("十月");
              header1.add("十一月");
              header1.add("十二月");
              header1.add("合计");
              writer.writeHeadRow(header1);
              List<List<String>> rows = new LinkedList<>();
              list.forEach(val -> {
				  Map<String,Object> map = val;
                  LinkedList<String> row = CollUtil.newLinkedList(map.get("hosname").toString(),map.get("doctorName").toString(),map.get("January").toString(),map.get("February").toString(),map.get("March").toString(),map.get("April").toString(),
						  map.get("May").toString(),map.get("June").toString(),map.get("July").toString(),map.get("August").toString(),
						  map.get("September").toString(),map.get("October").toString(),map.get("November").toString(),map.get("December").toString(),map.get("Total").toString());
				  rows.add(row);
              });
              writer.write(rows,true);
			 writer.setColumnWidth(0,50);

			 response.setContentType("application/vnd.ms-excel;charset=utf-8");
              String fileName = new String("月度工作量统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
              response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
              ServletOutputStream out = null;
              try {
                   out = response.getOutputStream();
                   writer.flush(out, true);
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   // 关闭writer，释放内存
                   writer.close();
              }
              //此处记得关闭输出Servlet流
              IoUtil.close(out);

         } catch (Exception e) {
              e.printStackTrace();
         }
    }

	@RequestMapping("/exportBzcx")
    public void exportBzcx(HttpServletRequest request, HttpServletResponse response){
         try {
              List<Codelist> chronicList = iCodelistService.getChronicList();

              ExcelWriter writer = ExcelUtil.getWriter();
              List<String> header0 = new LinkedList<>();
              /*header0.add("慢病病种查询");
              writer.writeHeadRow(header0);
              writer.merge(0,0,0,1,null,false);*/
              List<String> header1 = new LinkedList<>();
              header1.add("序号");
              header1.add("病症名称");
              writer.writeHeadRow(header1);
              List<List<String>> rows = new LinkedList<>();
              for(int i=0;i<chronicList.size();i++){
				  LinkedList<String> row = CollUtil.newLinkedList((i+1)+"",chronicList.get(i).getCodeName());
				  rows.add(row);
              }
              writer.write(rows,true);


			 response.setContentType("application/vnd.ms-excel;charset=utf-8");
              String fileName = new String("慢病病种查询".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
              response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
              ServletOutputStream out = null;
              try {
                   out = response.getOutputStream();
                   writer.flush(out, true);
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   // 关闭writer，释放内存
                   writer.close();
              }
              //此处记得关闭输出Servlet流
              IoUtil.close(out);

         } catch (Exception e) {
              e.printStackTrace();
         }
    }

	/**
	 * 左侧树
	 * @param hosnum
	 * @return
	 */
   @RequestMapping("/geteCunRenShu")
   public List<Map<String,Object>> geteCunRenShu(HttpServletRequest request, HttpServletResponse response){
	   //医院编号
	   String hosnum = request.getParameter("hosnum");
        return followupRecordService.geteCunRenShu(hosnum);
   }

}
